﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CatSimulator
{
    public class WizardController
    {
        private ArrayList WizardForms = new ArrayList();
        private int curIndex = 0;

        #region 构造函数
        /// <summary>
        ///构造函数
        /// </summary>
        public WizardController()
        {
            //基本设置
            WizardForms.Add(new StepBasic());
            //账号设置
            WizardForms.Add(new StepAccount());
            //键盘设置
            WizardForms.Add(new StepKeyRate()); //frmStep1继承自FormBase
         
           
            foreach (FormBase frm in WizardForms)
            {
                frm.controller = this;
                frm.DisableButton();
            }
        }
        #endregion

        #region 自定义函数
        /// <summary>
        /// 自定义函数
        /// </summary>

        public bool IsFirstForm //属性
        {
            get { return curIndex == 0; }
        }
        public bool IsLastForm //属性
        {
            get { return curIndex == this.WizardForms.Count - 1; }
        }

        public void GoNext()
        {
            if (curIndex + 1 < WizardForms.Count)
            {
                ((FormBase)WizardForms[curIndex]).Visible = false;
                curIndex++;
            }
            else
            {
                return;
            }
            ((FormBase)WizardForms[curIndex]).Show();
            ((FormBase)WizardForms[curIndex]).DisableButton();
        }

        public void GoPrev()
        {
            if (curIndex - 1 >= 0)
            {
                ((FormBase)WizardForms[curIndex]).Visible = false;
                curIndex--;
            }
            else
            {
                return;
            }
            ((FormBase)WizardForms[curIndex]).Show();
            ((FormBase)WizardForms[curIndex]).DisableButton();
        }

        public void BeginWizard()
        {
            ((FormBase)WizardForms[0]).Show();
            ((FormBase)WizardForms[curIndex]).DisableButton();
        }

        public void FinishWizard()
        {
            curIndex = 0;
            Dispose();
        }

        private void Dispose()
        {
            foreach (FormBase frm in WizardForms)
            {
                frm.Close();
            }
        }
        #endregion
    }
}
